package com.eatme.web.app.coupon.template.converter;

import com.alibaba.fastjson2.JSON;
import com.eatme.web.app.coupon.common.vo.TemplateRule;

import javax.persistence.AttributeConverter;
import javax.persistence.Convert;

/**
 * 优惠券规则属性转换器
 */
@Convert
public class TemplateRuleConverter implements AttributeConverter<TemplateRule,String> {
    @Override
    public String convertToDatabaseColumn(TemplateRule templateRule) {
        return JSON.toJSONString(templateRule);
    }

    @Override
    public TemplateRule convertToEntityAttribute(String rule) {
        return JSON.parseObject(rule,TemplateRule.class);
    }
}
